import { makeAutoObservable, flow, action, observable } from "mobx";

const DEFAULT: number[] = [];
const DEFAULT_MARK: number[][] = [];
for (let i = 0; i < 81; i++) {
    DEFAULT.push(-1);
    DEFAULT_MARK.push([]);
}

export const DIFFICULTY_OPTIONS: {label: string, value: Difficulty | 'begin'}[] = [
    {label: '入门', value: 'begin'},
    {label: '简单', value: 'easy'},
    {label: '中等', value: 'medium'},
    {label: '困难', value: 'hard'},
    {label: '专家', value: 'expert'}
];

export default class SudokuStore {

    audioUrl = 'https://common-prd.oss-cn-hangzhou.aliyuncs.com/demo/audio/mozart-k545.mp4';

    difficulty: Difficulty = 'begin';

    origin: number[] = DEFAULT;

    puzzle: number[] = DEFAULT;

    solution: string = '';

    mark: number[][] = [];

    success: boolean = false;

    gameTime: string = '';

    errorItems: number[] = [];

    startTime: number = 0;

    checkTimes: number = 4;

    constructor() {
        makeAutoObservable(this, {}, { autoBind: true });
    }

    @action
    setDifficulty = (_d: Difficulty) => {
        this.difficulty = _d;
    }

    @action
    setOrigin = (_o: number[] | null) => {
        this.origin = _o || DEFAULT;
    }

    @action
    setPuzzle = (_p: number[] | null) => {
        this.puzzle = _p || DEFAULT;
    }

    @action
    setSolution = (_s: string) => {
        this.solution = _s;
    }

    @action
    setMark = (_m: number[][]) => {
        this.mark = _m;
    }

    @action
    setSuccess = (_s: boolean) => {
        this.success = _s;
    }

    @action
    setGameTime = (_t: string) => {
        this.gameTime = _t;
    }

    @action
    setErrorItems = (_e: number[]) => {
        this.errorItems = _e;
    }

    @action
    setStartTime = (_t: number) => {
        this.startTime = _t;
    }

    @action
    setCheckTimes = (_c: number) => {
        this.checkTimes = _c;
    }
}